<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>RTOS - a cooperative multitasking library: RTOS::task Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">RTOS - a cooperative multitasking library
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="class_r_t_o_s.html">RTOS</a>      </li>
      <li class="navelem"><a class="el" href="class_r_t_o_s_1_1task.html">task</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#friends">Friends</a>  </div>
  <div class="headertitle">
<div class="title">RTOS::task Class Reference</div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="RTOS::task" -->
<p>an independent thread of execution  
 <a href="class_r_t_o_s_1_1task.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="p_r_t_o_s_8h_source.html">pRTOS.h</a>&gt;</code></p>

<p><a href="class_r_t_o_s_1_1task-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ae50f0e253e66c53e3b28e388133c8fe7">task</a> (unsigned int priority=RTOS_MAX_PRIORITY, const char *tname=&quot;&quot;, unsigned int stacksize=RTOS_DEFAULT_STACK_SIZE)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">constructor, specify priority, name and stacksize  <a href="#ae50f0e253e66c53e3b28e388133c8fe7"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a5035326ddaf51d9219a17ca6c5a23c83"></a><!-- doxytag: member="RTOS::task::~task" ref="a5035326ddaf51d9219a17ca6c5a23c83" args="(void)" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a5035326ddaf51d9219a17ca6c5a23c83">~task</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">throws an error, beacuse tasks should never be destroyed <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a80f429fbecc2cc2e8516121461df44e6">suspend</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">suspend a task (prevent execution until a resume)  <a href="#a80f429fbecc2cc2e8516121461df44e6"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a8f3e75810d12a7d8ac3a423cc32f4dfa">resume</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">continue a suspended task  <a href="#a8f3e75810d12a7d8ac3a423cc32f4dfa"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#aa3eec7220a2724d30e2156cc395035f2">release</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">release the CPU to the scheduler  <a href="#aa3eec7220a2724d30e2156cc395035f2"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4">sleep</a> (unsigned int time)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">wait for some time  <a href="#a9d639b6f1147e0e3dbc603cdd8c52bd4"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ac5a30dff650f3b714491509cabad5dff"></a><!-- doxytag: member="RTOS::task::priority" ref="ac5a30dff650f3b714491509cabad5dff" args="(void) const " -->
unsigned int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ac5a30dff650f3b714491509cabad5dff">priority</a> (void) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">report the task priority <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ae41e86737164ab73a142ea8e9d3f95b4"></a><!-- doxytag: member="RTOS::task::name" ref="ae41e86737164ab73a142ea8e9d3f95b4" args="(void) const " -->
const char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ae41e86737164ab73a142ea8e9d3f95b4">name</a> (void) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">report the task name <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ab02fe6432956956957bb2629dc9a3031"></a><!-- doxytag: member="RTOS::task::is_suspended" ref="ab02fe6432956956957bb2629dc9a3031" args="(void) const " -->
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ab02fe6432956956957bb2629dc9a3031">is_suspended</a> (void) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">report whether the task is currently suspended <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a1e0b2566b673b0e4e6efd63a80284d35"></a><!-- doxytag: member="RTOS::task::is_blocked" ref="a1e0b2566b673b0e4e6efd63a80284d35" args="(void) const " -->
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a1e0b2566b673b0e4e6efd63a80284d35">is_blocked</a> (void) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">report whether the task is currently blocked <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8ec666474a7668f78da3438dfa818a8e"></a><!-- doxytag: member="RTOS::task::is_ready" ref="a8ec666474a7668f78da3438dfa818a8e" args="(void) const " -->
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a8ec666474a7668f78da3438dfa818a8e">is_ready</a> (void) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">report whether the task is currently ready for execution <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a76913289a89a86fcf40171e28bfcfe98"></a><!-- doxytag: member="RTOS::task::logging_set" ref="a76913289a89a86fcf40171e28bfcfe98" args="(bool log)" -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a76913289a89a86fcf40171e28bfcfe98">logging_set</a> (bool log)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">for debugging: switch logging on or off <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ac94209dd2efea030a70d48dabc890f38"></a><!-- doxytag: member="RTOS::task::print" ref="ac94209dd2efea030a70d48dabc890f38" args="(std::ostream &amp;stream, bool header=true) const " -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ac94209dd2efea030a70d48dabc890f38">print</a> (std::ostream &amp;stream, bool header=true) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">print task statistics <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="class_r_t_o_s_1_1event.html">event</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a6fc603d0f1c8a94813586d3dfd123fcc">wait</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">wait for all waitables created for this task  <a href="#a6fc603d0f1c8a94813586d3dfd123fcc"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="class_r_t_o_s_1_1event.html">event</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a7b20fada91e6d232f6791ebc9675e3fc">wait</a> (const <a class="el" href="class_r_t_o_s_1_1waitable.html">waitable</a> &amp;w)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">wait for a single waitable  <a href="#a7b20fada91e6d232f6791ebc9675e3fc"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="class_r_t_o_s_1_1event.html">event</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a09111916c62632df3042f5991ac7ab42">wait</a> (const <a class="el" href="class_r_t_o_s_1_1event.html">event</a> &amp;set)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">wait for a set of waitables  <a href="#a09111916c62632df3042f5991ac7ab42"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aebeb5ca826f7137a66474bbee3bf74a1"></a><!-- doxytag: member="RTOS::task::set" ref="aebeb5ca826f7137a66474bbee3bf74a1" args="(flag &amp;w)" -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#aebeb5ca826f7137a66474bbee3bf74a1">set</a> (<a class="el" href="class_r_t_o_s_1_1flag.html">flag</a> &amp;w)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">set a flag <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a0ea383a40c40d9f69fe8e29fb36fa40d">ignore_activation_time</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">ignore this activation for the statistics  <a href="#a0ea383a40c40d9f69fe8e29fb36fa40d"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d">main</a> (void)=0</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">task body, must be provided by a derived class  <a href="#addc6d52f8792ddba1158d7ae5ef0037d"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="friends"></a>
Friends</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a01d2f5a71b8cd797b5f01fb6940ea353"></a><!-- doxytag: member="RTOS::task::periodic_task" ref="a01d2f5a71b8cd797b5f01fb6940ea353" args="" -->
class&#160;</td><td class="memItemRight" valign="bottom"><b>periodic_task</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a0ee29d8961a0b67cea2c3fa76da116da"></a><!-- doxytag: member="RTOS::task::waitable_set" ref="a0ee29d8961a0b67cea2c3fa76da116da" args="" -->
class&#160;</td><td class="memItemRight" valign="bottom"><b>waitable_set</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a2d8be07618a92a592c4905e969f9927f"></a><!-- doxytag: member="RTOS::task::flag" ref="a2d8be07618a92a592c4905e969f9927f" args="" -->
class&#160;</td><td class="memItemRight" valign="bottom"><b>flag</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa5b30b5b619f01a5d94b779bf0e58610"></a><!-- doxytag: member="RTOS::task::RTOS" ref="aa5b30b5b619f01a5d94b779bf0e58610" args="" -->
class&#160;</td><td class="memItemRight" valign="bottom"><b>RTOS</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a972487b0f63ae9fefb7f6642dae2d452"></a><!-- doxytag: member="RTOS::task::task_trampoline" ref="a972487b0f63ae9fefb7f6642dae2d452" args="(void)" -->
void&#160;</td><td class="memItemRight" valign="bottom"><b>task_trampoline</b> (void)</td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>an independent thread of execution </p>
<p>A task is an independent thread of execution, using its own stack. Tasks share the single CPU, so only one task can be running at any time. The <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> determines which task is running. A task has two bi-value states that determine whether the task is runnable: the suspended/resumed flag and the waiting/non-waiting flag. A task is runnable only when it is both resumed, and non-waiting. When a task is created it is resumed and non-waiting. ll tasks (and the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> code) run in the same memory space, without protection from each other. So a 'wild pointer' in one task can destroy data in another task, or even in the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a>.</p>
<p>Each task is created with a fixed priority, which can be any unsigend integer value below RTOS_MAX_PRIORITY (by default 10_000). After creation the priority can not be changed. The value 0 indicates the highest task priority, a higher number indicates a lower priority. Each task must have a unqiue priority, it is an error to create a task with same priority as an existing task. You can omit the priority, in which case the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> will select an unused priority starting at RTOS_MAX_PRIORITY (in other words, it will choose a low priority for your task).</p>
<p>Each task has its own stack. You can specify the size of the stack at task creation. If you omit the stack size, RTOS_DEFAULT_STACK_SIZE will be used (default: 2 Kb). This will be enough for most tasks, if you take care not to allocate big things on the stack, and avoid very deep nesting (watch out for recursion!).</p>
<p>A task is created by instatiating a class that derives from <a class="el" href="class_r_t_o_s_1_1task.html" title="an independent thread of execution">RTOS::task</a> and supplies a <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main()</a>. This <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main()</a> should never return. The fragment below shows how you can do this. The task name is used for statistics and debugging. As shown for the name, it might be wise to get the task parameters as arguments to the constructor of your task.</p>
<div class="fragment"><pre class="fragment"> <span class="keyword">class </span>my_task_class : <span class="keyword">public</span> <a class="code" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a>::task {
 <span class="keyword">public</span>:
    my_task_class( <span class="keyword">const</span> <span class="keywordtype">char</span> *<a class="code" href="class_r_t_o_s_1_1task.html#ae41e86737164ab73a142ea8e9d3f95b4" title="report the task name">name</a> ): 
       task( 
          name,  <span class="comment">// name of the task</span>
          10,    <span class="comment">// task priority</span>
          4096   <span class="comment">// task stack size</span>
       ){}
 <span class="keyword">private</span>:
    <span class="keywordtype">void</span> <a class="code" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main</a>( <span class="keywordtype">void</span> ){
       <span class="comment">// put the code of your task here</span>
    }
 };
 my_task_class my_task( <span class="stringliteral">&quot;my first task&quot;</span> );
 my_task_class my_task( <span class="stringliteral">&quot;my second task&quot;</span> );
</pre></div><p>The example below is a complete program that shows the standard part (initialization, and a main that calls <a class="el" href="class_r_t_o_s.html#a354317abf0afae8b4d228eb63e76e71b" title="runs the scheduler">RTOS::run()</a>), a function for writing to an individual LED, a task class that blinks a LED, and two instatiations of this class. Note that the <a class="el" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4" title="wait for some time">sleep()</a> is call used instead of mkt_wait_ms or mkt_wait_us. Sleep() causes other tasks to run while this taks is waiting, whereas the mkt_wait_* calls would use monopolize the CPU to do a busy wait.</p>
<p>Subseqent examples will not show the standard initialization (the part up to the comment line).</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #configure board        hu_arm_v4</span>
<span class="preprocessor"></span><span class="preprocessor"> #configure clcd_lines   2</span>
<span class="preprocessor"></span><span class="preprocessor"> #configure memory       rom</span>
<span class="preprocessor"></span><span class="preprocessor"> #configure baudrate     38400</span>
<span class="preprocessor"></span> 
<span class="preprocessor"> #include &quot;pRTOS.h&quot;</span>
 
 <span class="keywordtype">int</span> <a class="code" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main</a>( <span class="keywordtype">void</span> ){
    <a class="code" href="class_r_t_o_s.html#a354317abf0afae8b4d228eb63e76e71b" title="runs the scheduler">RTOS::run</a>();
    <span class="keywordflow">return</span> 0;
 }
 
 <span class="comment">// end of standard part</span>
 
 <span class="keywordtype">void</span> led_set( <span class="keywordtype">int</span> n, <span class="keywordtype">int</span> v ){
    <span class="keyword">static</span> <span class="keywordtype">int</span> leds = 0;   
    <span class="keywordflow">if</span>( v ){ leds |= 1 &lt;&lt; n; } <span class="keywordflow">else</span> { leds &amp;=~ 1 &lt;&lt; n; }
    mkt_leds_write( leds );
 }
 
 <span class="keyword">class </span>blinker : <span class="keyword">public</span> <a class="code" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a>::task {
 <span class="keyword">public</span>:
    blinker( <span class="keywordtype">int</span> LED, <span class="keywordtype">int</span> period ): 
       LED( LED ), period( period ){}
 <span class="keyword">private</span>:
    <span class="keywordtype">int</span> LED, period;
    <span class="keywordtype">void</span> <a class="code" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main</a>( <span class="keywordtype">void</span> ){
       <span class="keywordflow">for</span>(;;){
          led_set( LED, 1 );
          <a class="code" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4" title="wait for some time">sleep</a>( period / 2 );
          led_set( LED, 0 );
          <a class="code" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4" title="wait for some time">sleep</a>( period / 2 );
       }
    }
 };
 
 blinker led0( 0, 1000 MS );
 blinker led1( 1,  300 MS );
</pre></div><p>A task can be suspended and resumed by the <a class="el" href="class_r_t_o_s_1_1task.html#a80f429fbecc2cc2e8516121461df44e6" title="suspend a task (prevent execution until a resume)">task::suspend()</a> and <a class="el" href="class_r_t_o_s_1_1task.html#a8f3e75810d12a7d8ac3a423cc32f4dfa" title="continue a suspended task">task::resume()</a> calls. The suspend/resume state does not count the number of suspends and resumes: a suspend call on an already suspended task (or a resume on an already resumed task) has no effect. Suspend and resume are intended for use by the application code: the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> will never suspend or resume a task. (The <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> uses the waiting/non-waiting state, which can not be changed directly by the application.)</p>
<p>The example below shows one task that beeps the speaker at 1 kHz, while the other taks suspends and resumes the first task to make it beep 5 times, after which it suspends itself, which ends all activity. (This will trigger the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> deadlock detection, because a normal embedded application should never terminate.)</p>
<div class="fragment"><pre class="fragment"> <span class="keyword">class </span>beeper : <span class="keyword">public</span> <a class="code" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a>::task {
 <span class="keyword">public</span>:
    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> speaker;
    beeper( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> speaker ): speaker( speaker ){}
    <span class="keywordtype">void</span> <a class="code" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main</a>( <span class="keywordtype">void</span> ){
       mkt_pin_configure( speaker, mkt_output);
       <span class="keywordflow">for</span>(;;){
          mkt_pin_write( speaker, 1  );
          <a class="code" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4" title="wait for some time">sleep</a>( 500 US );
          mkt_pin_write( speaker, 0  );
          <a class="code" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4" title="wait for some time">sleep</a>( 500 US );
       }
    }
 };
 beeper speaker( 10 );
 
 <span class="keyword">class </span>suspender : <span class="keyword">public</span> <a class="code" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a>::task {
    <span class="keywordtype">void</span> <a class="code" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main</a>( <span class="keywordtype">void</span> ){
       <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; 5 ; i++ ){
          speaker.resume();
          <a class="code" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4" title="wait for some time">sleep</a>( 500 MS );
          speaker.suspend();
          <a class="code" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4" title="wait for some time">sleep</a>( 1 S );
       }
       <a class="code" href="class_r_t_o_s_1_1task.html#a80f429fbecc2cc2e8516121461df44e6" title="suspend a task (prevent execution until a resume)">suspend</a>();
    }
 };
 suspender task2; 
</pre></div> </div><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="ae50f0e253e66c53e3b28e388133c8fe7"></a><!-- doxytag: member="RTOS::task::task" ref="ae50f0e253e66c53e3b28e388133c8fe7" args="(unsigned int priority=RTOS_MAX_PRIORITY, const char *tname=&quot;&quot;, unsigned int stacksize=RTOS_DEFAULT_STACK_SIZE)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">RTOS::task::task </td>
          <td>(</td>
          <td class="paramtype">unsigned int&#160;</td>
          <td class="paramname"><em>priority</em> = <code>RTOS_MAX_PRIORITY</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>tname</em> = <code>&quot;&quot;</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned int&#160;</td>
          <td class="paramname"><em>stacksize</em> = <code>RTOS_DEFAULT_STACK_SIZE</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>constructor, specify priority, name and stacksize </p>
<p>Priorities are reasonably-valued (below RTOS_DEFAULT_RIORITY) unsigned integers. 0 is te highest priority. Priorities must be unqiue. The default causes the constructor to choose a free priority starting at RTOS_DEFAULT_PRIORITY (default: 10000).</p>
<p>The name is used for debugging and statistics.</p>
<p>A stack of stack_size bytes is allocated for the task. The default is 2 kB. </p>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a0ea383a40c40d9f69fe8e29fb36fa40d"></a><!-- doxytag: member="RTOS::task::ignore_activation_time" ref="a0ea383a40c40d9f69fe8e29fb36fa40d" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::task::ignore_activation_time </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>ignore this activation for the statistics </p>
<p>Calling this function makes the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> statistics ignore the current task activation as far as statistics is concerned. You can use this to avoid pullution of your task statistics with the timing effects of debug logging. But make sure you don't use it in the 'normal' execution paths, becaue that would make the statitics lie to you. </p>

</div>
</div>
<a class="anchor" id="addc6d52f8792ddba1158d7ae5ef0037d"></a><!-- doxytag: member="RTOS::task::main" ref="addc6d52f8792ddba1158d7ae5ef0037d" args="(void)=0" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual void RTOS::task::main </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [protected, pure virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>task body, must be provided by a derived class </p>
<p>A task is created by inheriting from task and providing a <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main()</a> function. Initialisation of the task, including creating its waitables, should be done in the constructor. Don't forget to call the constructor of the task class!</p>
<p>The <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main()</a> is the body of the task. It should never terminate.</p>
<p>Each task has a unique priority (an unsigned integer). A lower value indicates a higher priority. The <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> scheduler will always run the task with the higest-priority runnable (neither blocked nor suspended) task. A task runs until it changes this 'situation' by using an <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> call that changes its own state to not runnable, or the state of a higher priority task to runnable.</p>
<p>Timers are served only when the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> is activated by calling any of its state-changing interfaces. Hence the longest run time between such calls determines the granularity (timewise responsiveness) of the application. Within a timeconsuming computation a task can call <a class="el" href="class_r_t_o_s_1_1task.html#aa3eec7220a2724d30e2156cc395035f2" title="release the CPU to the scheduler">release()</a> to have the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> serve the timers. </p>

</div>
</div>
<a class="anchor" id="aa3eec7220a2724d30e2156cc395035f2"></a><!-- doxytag: member="RTOS::task::release" ref="aa3eec7220a2724d30e2156cc395035f2" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::task::release </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>release the CPU to the scheduler </p>
<p>Sevices timers and releases the CPU to a higher priority task if one became ready. </p>

</div>
</div>
<a class="anchor" id="a8f3e75810d12a7d8ac3a423cc32f4dfa"></a><!-- doxytag: member="RTOS::task::resume" ref="a8f3e75810d12a7d8ac3a423cc32f4dfa" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual void RTOS::task::resume </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>continue a suspended task </p>
<p>Has no effect when the task is not suspended.</p>
<p>Can be extended by an application task to suit its needs. </p>

</div>
</div>
<a class="anchor" id="a9d639b6f1147e0e3dbc603cdd8c52bd4"></a><!-- doxytag: member="RTOS::task::sleep" ref="a9d639b6f1147e0e3dbc603cdd8c52bd4" args="(unsigned int time)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::task::sleep </td>
          <td>(</td>
          <td class="paramtype">unsigned int&#160;</td>
          <td class="paramname"><em>time</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>wait for some time </p>
<p>Sleeps the task (prevents execution) for the indicated time. </p>

</div>
</div>
<a class="anchor" id="a80f429fbecc2cc2e8516121461df44e6"></a><!-- doxytag: member="RTOS::task::suspend" ref="a80f429fbecc2cc2e8516121461df44e6" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual void RTOS::task::suspend </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>suspend a task (prevent execution until a resume) </p>
<p>Suspends the task (prevents execution). Has no effect when the task is already suspended. Can be extended by an application task.</p>
<p>A concrete task can extend this operation to suit its needs. </p>

</div>
</div>
<a class="anchor" id="a6fc603d0f1c8a94813586d3dfd123fcc"></a><!-- doxytag: member="RTOS::task::wait" ref="a6fc603d0f1c8a94813586d3dfd123fcc" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_r_t_o_s_1_1event.html">event</a> RTOS::task::wait </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>wait for all waitables created for this task </p>
<p>Wait (prevent execution) until at least one of the waitables is set. Return and clear that waitable. Three variants for the parameter:</p>
<ul>
<li>The default (no parameter) waits for all waitables defined for the task.</li>
<li>One waitable as argument waits for that specific waitable.</li>
<li>The addition (operator+) of waitables: wait for any one of those waitables.</li>
</ul>
<p>It is an error to wait for waitables that have not been created for this task. </p>

</div>
</div>
<a class="anchor" id="a7b20fada91e6d232f6791ebc9675e3fc"></a><!-- doxytag: member="RTOS::task::wait" ref="a7b20fada91e6d232f6791ebc9675e3fc" args="(const waitable &amp;w)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_r_t_o_s_1_1event.html">event</a> RTOS::task::wait </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="class_r_t_o_s_1_1waitable.html">waitable</a> &amp;&#160;</td>
          <td class="paramname"><em>w</em></td><td>)</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>wait for a single waitable </p>
<p>Wait (prevent execution) until at least one of the waitables is set. Return and clear that waitable. Three variants for the parameter:</p>
<ul>
<li>The default (no parameter) waits for all waitables defined for the task.</li>
<li>One waitable as argument waits for that specific waitable.</li>
<li>The addition (operator+) of waitables: wait for any one of those waitables.</li>
</ul>
<p>It is an error to wait for waitables that have not been created for this task. </p>
 
</div>
</div>
<a class="anchor" id="a09111916c62632df3042f5991ac7ab42"></a><!-- doxytag: member="RTOS::task::wait" ref="a09111916c62632df3042f5991ac7ab42" args="(const event &amp;set)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_r_t_o_s_1_1event.html">event</a> RTOS::task::wait </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="class_r_t_o_s_1_1event.html">event</a> &amp;&#160;</td>
          <td class="paramname"><em>set</em></td><td>)</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>wait for a set of waitables </p>
<p>Wait (prevent execution) until at least one of the waitables is set. Return and clear that waitable. Three variants for the parameter:</p>
<ul>
<li>The default (no parameter) waits for all waitables defined for the task.</li>
<li>One waitable as argument waits for that specific waitable.</li>
<li>The addition (operator+) of waitables: wait for any one of those waitables.</li>
</ul>
<p>It is an error to wait for waitables that have not been created for this task. </p>
 
</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="p_r_t_o_s_8h_source.html">pRTOS.h</a></li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Sat Apr 14 2012 15:59:33 for RTOS - a cooperative multitasking library by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
